package playtest;

import java.io.PrintStream;

public aspect CarPropertiesAspect {
	PrintStream oStream = System.out;
	
	pointcut moves(Car c):
		target(c) 	&&
		call(void Car.setLoc*(int));
	
	pointcut onExit():
		call(void System.exit(int));
	
	pointcut checkBoundary(Car c, int x):
		target(c)	&&
		args(x) 	&&
		call(void Car.setLoc*(int));
	
	before(Car c): moves(c){
		oStream.println("[AJ]: About to move car!");
	}
	
	before(Car c, int x): checkBoundary(c, x){
		if(x > 60){
			try {
				throw new Exception("[AJ]: Car about to be moved out of boundaries!" + "(" + c.getLocX() + "," + c.getLocY() + ")");
			} catch (Exception e) {
				oStream.println(e.getMessage());
				e.printStackTrace();
			}
		}
	}
	
	after(Car c): moves(c){
		oStream.println("[AJ]: Car has been moved to: (" + c.getLocX() + "," + c.getLocY() + ")");
	}
	
	before(): onExit(){
		oStream.println("[AJ]: About to exit program");
	}
}
